<?php include 'login/Restrito.php';?>
<?php 
function convertDataEmDMA($dt)
	{
		$dia = substr($dt,8,2);
		$mes = substr($dt,5,2);
		$ano = substr($dt,0,4);
		$data = $dia."/".$mes."/".$ano;
		return $data;
	}
?>
<script type="text/javascript" src="agenda/ajax.js"></script>
<form method="post" action="agenda/AgendaCadastrar.php" >
             <br />
             <h3 align="center">Agendar Consulta</h3>
			  	<hr color="#0066FF" size="3px">
			    <br />
			 <div align="center" style="min-height: 350px; width:auto">
             <table width="700px" align="center">
              <tr>
              	<td>Nome do paciente</td>
              	<td><input type="text" name="txtnome" id="txtnome"/> 
              	<input type="button" name="btnPesquisar" value="Pesquisar" onclick="getDados();"/></td>
              </tr>
              <tr>
              	<td>Resultado</td>
              	<td><div id="Resultado"></div></td>
              </tr>
              
              <tr>
          		<td>Medico</td>
          		<td><select name="medico" >
          			<option selected >Selecione...</option>
          			<?php
							require "banco/ConexaoBanco.php";
							$query = mysql_query("SELECT * FROM medico");
							while($lista = mysql_fetch_array($query)) { ?> 
							<option value="<?php echo $lista['id_medico']; ?>"><?php echo $lista['m_nome']; ?></option>
						<?php } mysql_close();?>
          		</select>
	          	</td>
	          </tr>
                  <tr style="width: 100px;">
                    <td align="left">Data</td>
                    <td><input name="data" type="text" id="datepicker" size="30" value="<?php if (isset($_GET['d'])){echo convertDataEmDMA($_GET['d']);}?>"/></td>
                    
                </tr>
                <tr>
                	<td>Hora</td>
                    <td><select name="hora">
	                    <?php 
	                    $horario = array('08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00','11:30', '12:00', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00');
	                    for ($i = 0; $i < 18; $i++){
							if (isset($_GET['h'])) {
								if($horario[$i] == $_GET['h']){
									echo '<option value="'.$horario[$i].'" selected>'.$horario[$i].'</option>';
								}else{
							
									echo '<option value="'.$horario[$i].'">'.$horario[$i].'</option>';
								}
							}
							else{
									
								echo '<option value="'.$horario[$i].'">'.$horario[$i].'</option>';
							}
							
						}
	                    
	                    ?>
	                    	
	                    </select>
	                </td>
                </tr>
                <tr>
                    <td align="left">Tipo de Atendimento</td>
                    <td><select name="tipo">
                    	<option value="Consulta">Consulta</option>
                    	<option value="Exame">Exame</option>
                    	<option value="Raio-X">Raio-X</option>
                    	
                    </select></td>
                </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td align="left"><input type="submit" value="Agendar" class="botao" name="enviar"/><a href="?p=consultas-marcadas" style="margin-left: 80px; ">Voltar</a></td>
                </tr>
              </table>
              </div>
        </form> 